<%--
    Document   : index
    Created on : 19 juin 2010, 23:51:05
    Author     : marya
--%>

<%@page contentType="text/xml" pageEncoding="UTF-8"%>
<%@page import="org.restlet.resource.ClientResource" %>
<%@page import="org.restlet.representation.Representation" %>
<%@page import="org.restlet.ext.xml.DomRepresentation" %>
<%@page import="org.w3c.dom.Element" %>
<%@page import="org.w3c.dom.Node" %>
<%@page import="org.w3c.dom.NodeList" %>
<%@page import="java.util.List" %>
<%@page import="xmlws.helpers.WebService" %>
<%

request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
            ClientResource client = new ClientResource(WebService.federateur + "/contacts/" + request.getParameter("idContact"));

                client.delete();
                DomRepresentation representation = new DomRepresentation(client.get());
                Node element = representation.getDocument().getDocumentElement();
                out.println("<table>");
                NodeList childs = element.getChildNodes();
                    for (int j = 0; j < childs.getLength(); j++) {
                        Node child = childs.item(j);
                        String childName = child.getNodeName();
                        if (childName.equals("nom")) {
                            out.println("<tr><td>Nom : </td><td>" + child.getTextContent() + "</td></tr>");
                        } else if (childName.equals("prenom")) {
                            out.println("<tr><td>Prenom : </td><td>" + child.getTextContent() + "</td></tr>");

                        } else if (childName.equals("emails")) {
                            NodeList emails = child.getChildNodes();
                            for (int k = 0; k < emails.getLength(); k++) {
                                Node email = emails.item(k);
                                if (email.getAttributes().getNamedItem("type").getTextContent().equals("Home")) {
                                    out.println("<tr><td>Home Email : </td><td>" + email.getTextContent() + "</td></tr>");
                                }
                                if (email.getAttributes().getNamedItem("type").getTextContent().equals("Private")) {
                                    out.println("<tr><td>Private Email : </td><td>" + email.getTextContent() + "</td></tr>");
                                }
                                if (email.getAttributes().getNamedItem("type").getTextContent().equals("Work")) {
                                    out.println("<tr><td>Work Email : </td><td>" + email.getTextContent() + "</td></tr>");
                                }
                            }


                        } else if (childName.equals("tels")) {
                            NodeList tels = child.getChildNodes();
                            for (int k = 0; k < tels.getLength(); k++) {
                                Node tel = tels.item(k);
                                if (tel.getAttributes().getNamedItem("type").getTextContent().equals("Home")) {
                                    out.println("<tr><td>Home Tel : </td><td>" + tel.getTextContent() + "</td></tr>");
                                } else if (tel.getAttributes().getNamedItem("type").getTextContent().equals("Private")) {
                                    out.println("<tr><td>Private Tel : </td><td>" + tel.getTextContent() + "</td></tr>");
                                } else if (tel.getAttributes().getNamedItem("type").getTextContent().equals("Work")) {
                                    out.println("<tr><td>Work Tel : </td><td>" + tel.getTextContent() + "</td></tr>");
                                }

                            }



                        } else if (childName.equals("adresse")) {
                            NodeList adresse = child.getChildNodes();
                            for (int k = 0; k < adresse.getLength(); k++) {
                                Node childAdresse = adresse.item(k);
                                String childAdresseName = childAdresse.getNodeName();
                                if (childAdresseName.equals("voie")) {
                                    out.println("<tr><td>Voie : </td><td>" + childAdresse.getTextContent() + "</td></tr>");
                                } else if (childAdresseName.equals("ville")) {
                                    out.println("<tr><td>Ville : </td><td>" + childAdresse.getTextContent() + "</td></tr>");
                                } else if (childAdresseName.equals("codePostal")) {
                                    out.println("<tr><td>code Postal : </td><td>" + childAdresse.getTextContent() + "</td></tr>");
                                } else if (childAdresseName.equals("pays")) {
                                    out.println("<tr><td>pays : </td><td>" + childAdresse.getTextContent() + "</td></tr>");
                                }

                            }

                        }

                    }
                    out.println("<tr>");
                    out.println("<td colspan=\"2\">");
                    out.println("<a class='button' onclick=\"applyToModify_contact(" + request.getParameter("idContact") + ")\">Modifier</a>");

                    out.println("</td>");
                    out.println("</tr>");
                    out.println("<tr>");
                    out.println("<td colspan=\"2\">");
                    out.println("<a class='button' onclick=\"delete_contact(" + request.getParameter("idContact") + ")\">Modifier</a>");

                    out.println("</td>");
                    out.println("</tr>");
                    out.println("</table><br/>");








%>

